# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/5/4 17:47
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/h5_server.git
# @File    : my_path.py
# @Software: PyCharm
# @Version: 3.5.4
import sys
import os


class pathutil(object):
	"""路径处理工具类"""

	def __init__(self):
		# 判断调试模式
		debug_vars = dict((a, b) for a, b in os.environ.items()
		                  if a.find('IPYTHONENABLE') >= 0)
		# 根据不同场景获取根目录
		if len(debug_vars) > 0:
			"""当前为debug运行时"""
			self.rootPath = sys.path[2]
		elif getattr(sys, 'frozen', False):
			"""当前为exe运行时"""
			self.rootPath = os.getcwd()
		else:
			"""正常执行"""
			self.rootPath = sys.path[1]
		# 替换斜杠
		self.rootPath = self.rootPath.replace("\\", "/")

	def getPathFromResources(self, fileName):
		"""按照文件名拼接资源文件路径"""
		filePath = "%s/resources/%s" % (self.rootPath, fileName)
		return filePath


PathUtil = pathutil()
if __name__ == '__main__':
	"""测试"""
	# path = PathUtil.getPathFromResources("context.ini")
	print(PathUtil.rootPath)
